﻿@model BlogPostModel

@using System.Text;
@using Nop.Services.Blogs
@Html.ValidationSummary(true)
@Html.HiddenFor(model => model.Id)

<div id="blog-post-edit">
    <ul>
        <li @Html.RenderSelectedTabIndex(0, GetSelectedTabIndex())>
            @T("Admin.ContentManagement.Blog.BlogPosts.Info")
        </li>
        <li @Html.RenderSelectedTabIndex(1, GetSelectedTabIndex())>
            @T("Admin.Common.SEO")
        </li>
        <li @Html.RenderSelectedTabIndex(2, GetSelectedTabIndex())>
            @T("Admin.ContentManagement.News.NewsItems.Stores")
        </li>
    </ul>
    <div>
        @TabInfo()
    </div>
    <div>
        @TabSeo()
    </div>
    <div>
        @TabStores()
    </div>
</div>
<script>
    $(document).ready(function () {
        $("#blog-post-edit").kendoTabStrip({
            animation: {
                open: {
                    effects: "fadeIn"
                }
            },
            select: tabstrip_on_tab_select
        });
    });
</script>

@{
    //custom tabs
    var eventMessage = new AdminTabStripCreated(this.Html, "blog-post-edit");
    EngineContext.Current.Resolve<IEventPublisher>().Publish(eventMessage);
    foreach (var eventBlock in eventMessage.BlocksToRender)
    {
        @eventBlock
    }
}

@*save selected tab index*@
<input type="hidden" id="selected-tab-index" name="selected-tab-index" value="@(GetSelectedTabIndex())">

@{
    //resources for product tags input
    Html.AppendCssFileParts("~/Content/tagit/jquery.tagit.css");
    Html.AppendScriptParts("~/Scripts/tag-it.min.js");
}
@helper TabInfo()
{
       
<script type="text/javascript">
    @{
        //TODO move to Model
        var productTags = EngineContext.Current.Resolve<IBlogService>().GetAllBlogPostTags(0, 0, true);
        var productTagsSb = new StringBuilder();
        productTagsSb.Append("var sampleTags = [");
        for (int i = 0; i < productTags.Count; i++)
        {
            var tag = productTags[i];
            productTagsSb.Append("'");
            productTagsSb.Append(HttpUtility.JavaScriptStringEncode(tag.Name));
            productTagsSb.Append("'");
            if (i != productTags.Count - 1)
            {
                productTagsSb.Append(",");
            }
        }
        productTagsSb.Append("]");
    }
    //product tags
    $(document).ready(function () {          
        @Html.Raw(productTagsSb.ToString())
        $("#@Html.FieldIdFor(model => model.Tags)").tagit({
            availableTags: sampleTags,
            allowSpaces: true
        });
    });
</script>
    <table class="adminContent">
        <tr>
            <td class="adminTitle">
                @Html.NopLabelFor(model => model.LanguageId):
            </td>
            <td class="adminData">
                @Html.DropDownListFor(model => model.LanguageId, new SelectList(ViewBag.AllLanguages, "Id", "Name"))
            </td>
        </tr>
        <tr>
            <td class="adminTitle">
                @Html.NopLabelFor(model => model.Title):
            </td>
            <td class="adminData">
                @Html.EditorFor(model => model.Title)
                @Html.ValidationMessageFor(model => model.Title)
            </td>
        </tr>
        <tr>
            <td class="adminTitle">
                @Html.NopLabelFor(model => model.Body):
            </td>
            <td class="adminData">
                @Html.EditorFor(x => x.Body, "RichEditor")
                @Html.ValidationMessageFor(model => model.Body)
            </td>
        </tr>
        <tr>
            <td class="adminTitle">
                @Html.NopLabelFor(model => model.AllowComments):
            </td>
            <td class="adminData">
                @Html.EditorFor(model => model.AllowComments)
                @Html.ValidationMessageFor(model => model.AllowComments)
            </td>
        </tr>
        <tr>
            <td class="adminTitle">
                @Html.NopLabelFor(model => model.Tags):
            </td>
            <td class="adminData">
                @Html.EditorFor(model => model.Tags)
                @Html.ValidationMessageFor(model => model.Tags)
            </td>
        </tr>
        <tr>
            <td class="adminTitle">
                @Html.NopLabelFor(model => model.StartDate):
            </td>
            <td class="adminData">
                @Html.EditorFor(model => model.StartDate)
                @Html.ValidationMessageFor(model => model.StartDate)
            </td>
        </tr>
        <tr>
            <td class="adminTitle">
                @Html.NopLabelFor(model => model.EndDate):
            </td>
            <td class="adminData">
                @Html.EditorFor(model => model.EndDate)
                @Html.ValidationMessageFor(model => model.EndDate)
            </td>
        </tr>
    </table>
}
@helper TabSeo()
{
    <table class="adminContent">
        <tr>
            <td class="adminTitle">
                @Html.NopLabelFor(model => model.MetaKeywords):
            </td>
            <td class="adminData">
                @Html.EditorFor(x => x.MetaKeywords)
                @Html.ValidationMessageFor(model => model.MetaKeywords)
            </td>
        </tr>
        <tr>
            <td class="adminTitle">
                @Html.NopLabelFor(model => model.MetaDescription):
            </td>
            <td class="adminData">
                @Html.EditorFor(x => x.MetaDescription)
                @Html.ValidationMessageFor(model => model.MetaDescription)
            </td>
        </tr>
        <tr>
            <td class="adminTitle">
                @Html.NopLabelFor(model => model.MetaTitle):
            </td>
            <td class="adminData">
                @Html.EditorFor(x => x.MetaTitle)
                @Html.ValidationMessageFor(model => model.MetaTitle)
            </td>
        </tr>
        <tr>
            <td class="adminTitle">
                @Html.NopLabelFor(model => model.SeName):
            </td>
            <td class="adminData">
                @Html.EditorFor(model => model.SeName)
                @Html.ValidationMessageFor(model => model.SeName)
            </td>
        </tr>
    </table>
}

@helper TabStores()
{
    <script type="text/javascript">
        $(document).ready(function () {

            $("#@Html.FieldIdFor(model => model.LimitedToStores)").click(toggleStoreMapping);

            toggleStoreMapping();
        });


        function toggleStoreMapping() {
            if ($('#@Html.FieldIdFor(model => model.LimitedToStores)').is(':checked')) {
                $('#pnl-available-stores').show();
            }
            else {
                $('#pnl-available-stores').hide();
            }
        }

    </script>
    <table class="adminContent">
        <tr>
            <td class="adminTitle">
                @Html.NopLabelFor(model => model.LimitedToStores):
            </td>
            <td class="adminData">
                @Html.EditorFor(model => model.LimitedToStores)
                @Html.ValidationMessageFor(model => model.LimitedToStores)
            </td>
        </tr>
        <tr id="pnl-available-stores">
            <td class="adminTitle">
                @Html.NopLabelFor(model => model.AvailableStores):
            </td>
            <td class="adminData">
                @if (Model.AvailableStores != null && Model.AvailableStores.Count > 0)
                {
                    foreach (var store in Model.AvailableStores)
                    {
                    <div>
                        <input type="checkbox" name="SelectedStoreIds" value="@store.Id" checked="@(Model.SelectedStoreIds != null && Model.SelectedStoreIds.Contains(store.Id))" />@store.Name
                    </div>
                    }
                }
                else
                {
                    <div>No stores defined</div>
                }</td>
        </tr>
    </table>
}

